import { getToken } from "@/utils/cache";

const headers = () => {
	let headers = {
		'content-type': 'application/json',
		Authorization: ''
	};
	const token = getToken()
	if (token) {
		headers.Authorization = `Bearer ${token}`
	}
	return headers
}

// @ts-ignore
export const request = <T>(params : UniApp.RequestOptions): Promise<T> => {
	return new Promise((resolve, reject) => {
		// @ts-ignore
		uni.request({
			//url: `${Config.baseUrl}${params.url}`,
			...params,
			method: params.method || 'POST',
			timeout: params.timeout || 100000,
			header: headers(),
			success: (res) => {
				console.log('接口响应:', res);
				resolve(res)
			},
			fail: (err: any) => {
				console.log('错误信息:', err);
				reject(err)
			}
		});

	})
}
